import {Store} from 'iflux2';
import {message} from 'antd';

import OrderBasic from './actor/order-basic';

import {getSetup, saveOptionsSetup, saveSetup} from './webapi';

export default class AppStore extends Store{
  bindActor() {
    return [
      new OrderBasic
    ]
  }
  init = async () => {
    const {data, err} = await getSetup();
    this.dispatch('setup-init', data);
  }
  onSetting = (data) => {
    this.dispatch('on-setup', data);
  }
  onSave = async () => {
    const {err} = await saveSetup(this.state().toJS());
    if(!err) {
      message.success('保存成功')
    }
  }
  onSaveOptionsSetup = async (data) => {
    let params = this.state().get('orderOptionsRequest').merge(data);
    const {err} = await saveOptionsSetup(params.toJS())
    if(!err) {
      this.dispatch('on-setup', {orderOptionsRequest: params});
      message.success('保存成功')
    }
  }
}